/**
 * 
 */
package vn.support.core.dto;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author nttuyen
 *
 */
public class DataObject {
	private final String name;
	private final Map<String, Object> attributes;
	
	public DataObject(String name) {
		this.name = name;
		this.attributes = new HashMap<String, Object>();
	}
	
	public synchronized <T> void set(String name, T value) {
		this.attributes.put(name, value);
	}
	
    public synchronized void remove(String name) {
        this.attributes.remove(name);
    }

	@SuppressWarnings("unchecked")
	public synchronized <T> T get(String name) {
		if(this.attributes.containsKey(name)) {
			try {
				return (T)this.attributes.get(name);
			} catch (Exception e) {}
		}
		return null;
	}
	
	
	public synchronized String getName() {
		return this.name;
	}

	public synchronized Map<String, Object> getAttributes() {
		return this.attributes;
	}
}
